package repository

import (
	"context"
	"github.com/aphasia51/website/internal/domain"
	"github.com/aphasia51/website/internal/repository/dao"
)

type ChemicalRepository struct {
	dao *dao.ChemicalDAO
}

func NewChemicalRepository(dao *dao.ChemicalDAO) *ChemicalRepository {
	return &ChemicalRepository{
		dao: dao,
	}
}

func (cr *ChemicalRepository) Query(ctx context.Context, c domain.Chemical) ([]domain.Chemical, error) {
	chemicals, err := cr.dao.Query(ctx, c)
	if err != nil {
		return []domain.Chemical{}, nil
	}

	returnValue := make([]domain.Chemical, 0)
	for _, v := range chemicals {
		returnValue = append(returnValue, domain.Chemical{
			Name:     v.Name,
			DictName: v.DictName,
			Stock:    v.Stock,
			//Date:            v.Date,
			//Specification:   v.Specification,
			//ActualQuantity:  v.ActualQuantity,
			//StorageLocation: v.StorageLocation,
			//DateManufacture: v.DateManufacture,
			//CAS:             v.CAS,
			//LaboratoryRoom:  v.LaboratoryRoom,
		})
	}

	return returnValue, nil
}

func (cr *ChemicalRepository) Select(ctx context.Context) ([]domain.Chemical, error) {
	chemicals, err := cr.dao.Select(ctx)
	if err != nil {
		return []domain.Chemical{}, nil
	}

	returnValue := make([]domain.Chemical, 0)
	for _, v := range chemicals {
		returnValue = append(returnValue, domain.Chemical{
			Id:       v.Id,
			Name:     v.Name,
			DictName: v.DictName,
		})
	}

	return returnValue, nil
}
